/**
 * Copyright (C) 2020-2021   江西省农村信用社联合社
 * All rights reserved
 */
package com.liuyucheng.idea_springboot.config;

import com.liuyucheng.idea_springboot.job.ReadFtpFileJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定时任务配置,启动之后定时任务会被存储到数据库中,如果需要修改,先删除之前的任务
 */
@Configuration
public class QuartzConfiguration {

    /**
     * ===========================================================ReadFtpFileJob
     */
    // 使用jobDetail包装job
    @Bean
    public JobDetail ReadFtpFileJobDetail() {
        return JobBuilder.newJob(ReadFtpFileJob.class).withIdentity("readFtpFileJob").storeDurably().build();
    }

    // 把jobDetail注册到Cron表达式的trigger上去
    @Bean
    public Trigger ReadFtpFileJobTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 2 * * ? *");

        return TriggerBuilder.newTrigger()
                .forJob(ReadFtpFileJobDetail())
                .withIdentity("readFtpFileJobTrigger")
                .withSchedule(cronScheduleBuilder)
                .build();
    }


}
